package org.skyui.config;

import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.skyui.annotations.*;
import org.skyui.core.AccessControl;
import org.skyui.core.Menu;

import com.baycrypt.vaadinui.VaadinUIApplication;

public class NavigationConfig implements Serializable {

	private static final long serialVersionUID = 569488623427101984L;

	public NavigationConfig(Class menuConfig) {

		SkyNavigation annotation = (SkyNavigation) menuConfig
				.getAnnotation(SkyNavigation.class);
		if (annotation == null) {
			throw new IllegalArgumentException(
					"No SkyNavigation annotation present in " + menuConfig);
		}
		SkyMenu[] menus = annotation.menus();
		for (SkyMenu menu : menus) {
			for (SkyTab tab : menu.tabs()) {
				if (tab.beanClass().getAnnotation(SkyTable.class) != null) {
						BeansTableViewConfig.addToConfigMap(tab.beanClass());
				}
			}
			menuItems.add(new Menu(menu.name(), menu.iconFilename(), menu
					.roles(), menu.productEditions(), menu.tabs()));

		}
	}
	
	
	protected List<Menu> menuItems = new ArrayList<Menu>();

	public List<Menu> getMenuItems() {
		return this.menuItems;
	}
}
